package com.wanmait.movie.controller;

import com.wanmait.movie.entity.Actor;
import com.wanmait.movie.entity.Food;
import com.wanmait.movie.entity.VO.FoodVO;
import com.wanmait.movie.mapper.FoodMapper;
import com.wanmait.movie.service.FoodService;
import com.wanmait.movie.service.FoodToComboService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;
import java.util.List;

@RestController
@RequestMapping("manage/food")
public class ManageFoodController {
    @Resource
    private FoodService foodService;

    @GetMapping("list")
    public AjaxResult list(@Min(1) @RequestParam(required = false, defaultValue = "1")Integer pageNum,  @RequestParam(required = false, defaultValue = "5")Integer pageSize ){
        return AjaxResult.success(foodService.getFood(pageNum,pageSize));
    }

    @GetMapping("getfood")
    public AjaxResult getFood() {
        return AjaxResult.success(foodService.getFoods());
    }
    @GetMapping("deletefood")
    public AjaxResult deleteFood(Integer id){
     return AjaxResult.success(foodService.removeById(id));
    }
    @PostMapping("saveorupdate")
    public AjaxResult saveOrUpdate(@RequestBody Food food){
        if (!foodService.saveOrUpdate(food)){
            return AjaxResult.error(505,"添加或修改错误");
        }
        return AjaxResult.success(foodService.saveOrUpdate(food));
    }
}
